%% Fig. 3A Fraunhofer 44.9*
xoffset = 19;
voltToCurrent = 1129.068;
Area = 123;

figure(1);
clf;
data = A45a1;
pcolor(data.K2A * 897.1 - xoffset, repmat(data.K1V, 1,117)' / voltToCurrent / Area * 1e7, (data.L1 / 10) ./ (data.L3 / 1000));
shading interp;
xlim([-400, 400]);
ylim([0, 0.5]);
caxis([0, 70]);
map = GenerateColorScaleJunctions();
colormap(map);
hold all;

data = A45a2;
pcolor( data.K2A * 897.1 - xoffset, repmat(data.K1V, 1, 126)' / voltToCurrent  / Area * 1e7, (data.L1 / 10) ./ (data.L3 / 1000));
shading interp;

data = A45a3;
pcolor(data.K2A * 897.1 - xoffset, repmat(data.K1V, 1, 101)' / voltToCurrent / Area  * 1e7,  (data.L1 / 10) ./ (data.L3 / 1000));
shading interp;
data = A45a4;
pcolor( data.K2A * 897.1 - xoffset, repmat(data.K1V, 1, 67)' / voltToCurrent / Area  * 1e7, (data.L1 / 10) ./ (data.L3 / 1000));
shading interp;

flux = (-600:0.1:600) * 10e-6 * 28e-9 / 10000; % B * w * thickness in Tesla m^2
phi0 = 2.0678e-15;

plot((-600:0.1:600),3.5 * abs(sin(pi * flux/phi0) ./ (pi*flux / phi0)), 'color', 1*[1,1,1]);
xlim([-400, 400]);
ylim([0, 5]);

ylabel('Current / Area (uA)');
xlabel('Field (Oe)');



% I-V linecuts.
figure(3); clf;
Rn = 4.02;
colors = parula(10);

fieldList = [0, 20, 30, 57, 67, 86];

data = A45a2;
k = 1;
for i = 1:length(fieldList)
	[~, idx] = min(abs(data.K2A(:, 1) * 897.1 - xoffset - fieldList(i)));
	[~, midpt] = min(abs(data.K1A(idx, :))); 
 	plot(data.K1V / voltToCurrent * Rn * 1000, (data.DMM1(idx, :) - data.DMM1(idx, midpt)) / 10 * 1000, 'color', colors(k, :), 'linewidth', 2); 
	k = k+1;
	hold all;
end


fieldList = [140];

data = A45a3;
for i = 1:length(fieldList)
	[~, idx] = min(abs(data.K2A(:, 1) * 897.1 - xoffset - fieldList(i)));
	[~, midpt] = min(abs(data.K1A(idx, :))); 
 	plot(data.K1V / voltToCurrent * Rn * 1000, (data.DMM1(idx, :) - data.DMM1(idx, midpt)) / 10 * 1000,  'color', colors(k, :), 'linewidth', 2); 
	k = k+1;
	hold all;
end

legend('0 mT', '2.0 mT', '3.0 mT', '5.7 mT', '6.7 mT', '8.6 mT', '14.0 mT')

xlabel('I Rn (mV)');
ylabel('V (mV)')
ylim([0, 1]);
xlim([0, 0.25])

%% Fig. 3B: 46.3*
s = 0.25;
figure(1);
clf;

ItoG = 897.1;

data = A463a2;
pcolor(data.K2A  * 2.91 * 1000, (data.KFieldA + 0.0325) * ItoG, (data.L3 / 10) ./ (0.001/1406)); 
hold all;
shading interp;
pause(s)


ylabel('Field (G)');
xlabel('I Rn (mV)')

map = GenerateColorScaleJunctions();
colormap(map);

caxis([0, 50]);
title('20 K');

ylim([-0.07 * ItoG, 700]);
% xlim([0, 0.5]);

y = -700:0.1:700;
w = 10.4e-6 %width in um
arg = pi * y * w * 1.5e-9 / (10000 * 2.07e-15);
plot(0.8 * sin(arg) ./ arg, y, '--' , 'color', [1,0,0], 'linewidth', 2);
arg = pi * y * w * 15e-9 / (10000 * 2.07e-15);
plot(abs(1.9 * sin(arg) ./ arg), y , '--', 'color', [1,1,1], 'linewidth', 0.1);



% Fig. 3B Inset: Line cuts at 20K
figure(2);
hold off;
fieldsToPlot = [0, 323];
colors = jet(length(fieldsToPlot));
for i = 1:length(fieldsToPlot)
    [~, idx] = min(abs((A463a2.KFieldA + 0.0325) * 897.1 - fieldsToPlot(i)))
    plot(A463a2.K2A(idx, :) * 2.91 * 1000, (A463a2.DMM2(idx, :) - A463a2.DMM2(idx, 1)) / 10 * 1000, 'color', colors(i, :), 'linewidth', 2)
    hold all;
end
xlabel('Current (\muA)');
ylabel('Voltage (mA)');
title('20K');
legend('0 G','323 G');


%% Fig. S16A 43* Fraunhofer
s = 0;
figure(2);
clf;
pcolor(repmat(A43b1_1.Field, 1, 43) * 10, A43b1_1.K1A / 111 * 1e6 / 10, (A43b1_1.L1 / 10) ./ (A43b1_1.L2 / 1000));
shading interp;
ylabel('Current (mA)');
xlabel('Field (kG)');
xlim([0, 3]*10);
ylim([0, 0.175]);
pause(s);

hold all;
pcolor(repmat(A43a1.K2A, 1, 43) * 897.1 / 10000 * 10, A43a1.K1A / 111 * 1e6 / 10, (A43a1.L1 / 10) ./ (A43a1.L2 / 1000)); shading interp; pause(s);

pcolor(repmat(A43b2.Field, 1,43) * 10, A43b2.K1A / 111 * 1e6 / 10,  (A43b2.L1 / 10) ./ (A43b2.L2 / 1000)); shading interp; pause(s);
pcolor(repmat(A43b3.Field, 1, 31) * 10, A43b3.K1A  / 111 * 1e6 / 10,  (A43b3.L1 / 10) ./ (A43b3.L2 / 1000)); shading interp; pause(s);
pcolor(repmat(A43b3_1.Field, 1, 31) * 10, A43b3_1.K1A / 111 * 1e6/ 10,  (A43b3_1.L1 / 10) ./ (A43b3_1.L2 / 1000)); shading interp; pause(s);

pcolor(repmat(A43b4.Field, 1, 31 ) * 10, A43b4.K1A / 111 * 1e6 / 10,  (A43b4.L1 / 10) ./ (A43b4.L2 / 1000)); shading interp; pause(s);


title('45K');
caxis([0, 55]);

hold all;

%% Fig. S16C: 43.8*
figure(1); clf;

Rn = 1.8;

data = A438b1;
pcolor(repmat(data.KFieldA, 1, 101) * 897.1, data.K1A * Rn * 1000, (data.L1 / 10) ./ (data.L2 / 1000) / Rn);
shading interp;
hold all;

data = A438b3;
pcolor(repmat(data.KFieldA, 1, 62) * 897.1, data.K1A * Rn * 1000, (data.L1 / 10) ./ (data.L2 / 1000) / Rn);
shading interp;

xlim([0, 1.5] * 10000);
caxis([0, 10]);
ylabel('I R_N (mV)');
xlabel('Field (G)');
title('50K');

xlim([-200, 200]);
ylim([0, 1.4]);

%% Fig. S16B/D
figure(1);
clf;
offset = -39;
Rn = 16.6; % Ohms, measured just under Tc.

pcolor(repmat(A432446a1.KField, 1, 30) * 897.1 - offset, A432446a1.K2A * Rn * 1000,  (A432446a1.L1 / 100) ./ (A432446a1.L2 / 1000) / Rn); hold all;
pcolor(repmat(A432446a2.KField, 1, 119) * 897.1 - offset, A432446a2.K2A * Rn * 1000, (A432446a2.L1 / 100) ./ (A432446a2.L2 / 1000) / Rn)
pcolor(repmat(A432446a3.KField, 1, 45) * 897.1 - offset, A432446a3.K2A * Rn * 1000, (A432446a3.L1 / 100) ./ (A432446a3.L2 / 1000) / Rn)
pcolor(repmat(A432446a4.KField, 1, 45) * 897.1 - offset, A432446a4.K2A * Rn * 1000, (A432446a4.L1 / 100) ./ (A432446a4.L2 / 1000) / Rn)


shading interp;
caxis([0, 20]);
map = GenerateColorScaleJunctions();
colormap(map);


xlim([-250, 450]);
ylim([0, 5]);

ylabel('I Rn (mV)');
xlabel('B_{||} (G)'); 

B = -500:0.1:500;
 flux = B * 8.5e-6 * 28e-9 / 10000;
 plot(B, abs(3.5 * sin(pi * flux / 2.0678e-15) ./ (pi * flux / 2.0678e-15)), 'color', 0.5*[1,1,1]);

shading interp;
caxis([0, 20]);
map = GenerateColorScaleJunctions();
colormap(map);


%% Fig. S16B/D
figure(1);
clf;
offset = -46;
Rn = 3.18; % Ohms, measured just under Tc.

pcolor(repmat(A432446a1.KField, 1, 30) * 897.1 - offset, repmat((0.001579 * A432446a1.Y1V - 1.7756e-5)', 81, 1) * Rn * 1000,  (A432446a1.L3 / 100) / 8.7e-7 / Rn); hold all;
pcolor(repmat(A432446a2.KField, 1, 119) * 897.1 - offset, repmat((0.001579 * A432446a2.Y1V - 1.7756e-5)', 157, 1) * Rn * 1000, (A432446a2.L3 / 100) / 8.7e-7 / Rn)
pcolor(repmat(A432446a3.KField, 1, 45) * 897.1 - offset, repmat((0.001579 * A432446a3.Y1V - 1.7756e-5)', 61, 1) * Rn * 1000, (A432446a3.L3 / 100) / 8.7e-7 / Rn)
pcolor(repmat(A432446a4.KField, 1, 45) * 897.1 - offset, repmat((0.001579 * A432446a4.Y1V - 1.7756e-5)', 81, 1) * Rn * 1000, (A432446a4.L3 / 100) / 8.7e-7 / Rn)

shading interp;
caxis([0, 20]);
map = GenerateColorScaleJunctions();
colormap(map);

xlim([-250, 450]);
ylim([0, 0.8]);

ylabel('I Rn (mV)');
xlabel('B_{||} (G)'); 

B = -500:0.1:500;
 flux = B * 7e-6 * 40e-9 / 10000;
 plot(B, abs(0.55 * sin(pi * flux / 2.0678e-15) ./ (pi * flux / 2.0678e-15)), 'color', 0.5*[1,1,1]);
title('6K')


shading interp;
caxis([0, 20]);
map = GenerateColorScaleJunctions();
colormap(map);